﻿// Inner Fire 游戏引擎库
// SkinMeshObject - 骨骼动画对象
//
// Copyright (c) 2025 by 尔西大帝. All rights reserved.
//
// 所属层级：应用层（4）
// 用于配置一个SkinMesh的游戏对象
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2025-03-12

#include "skin_mesh_object.h"

namespace ifire::game {
SkinMeshObject::SkinMeshObject(
    ikit::sstr name, Scene* scene, GameObject* parent)
    : GameObject(name, scene, parent) {}
SkinMeshObject::~SkinMeshObject() {}

void SkinMeshObject::FixedUpdate() { GameObject::FixedUpdate(); }

void SkinMeshObject::AddRenderItem(dx::RenderItem* item) {
  render_items_.push_back(item);
}

Armature* SkinMeshObject::GetArmature() {
  return GetModel()->GetArmature(); }

dx::SkinAnimator* SkinMeshObject::GetSkinAnimator() {
  return GetAnimator();
}

void SkinMeshObject::PrintInfo(ikit::sstr info_type) {
  static const ikit::sstr TYPE_NODE("Node");

  if (info_type == TYPE_NODE) {
    GetModel()->GetArmature()->PrintNode();
  }

  // 没有处理完的信息返回父级
  GameObject::PrintInfo(info_type);
}

void SkinMeshObject::UpdateTransform() {
  GameObject::UpdateTransform();
  SetRenderMatrix(transform_.mat);  
}

void SkinMeshObject::SetRenderMatrix(FMat mat) {
  for (auto e : render_items_){
    e->SetWorldMatrix(mat);
  }
}

} // namespace ifire::game